package opl.ui.adapters;

import java.util.List;

import opl.entities.NotificationDetails;
import opl.ui.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class NotificationAdapter extends ArrayAdapter<NotificationDetails> {

	private static int notificationTemplate;
	private List<NotificationDetails> lstNotifications;
	private LayoutInflater lf;

	static {
		notificationTemplate = R.layout.notification_template;
	}

	public NotificationAdapter(Context context,
			List<NotificationDetails> objects) {
		super(context, notificationTemplate, objects);

		lstNotifications = objects;
		lf = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView=lf.inflate(notificationTemplate, null);
		}

		TextView tvCaption=(TextView) convertView.findViewById(R.id.tvCaption);
		TextView tvDescription=(TextView) convertView.findViewById(R.id.tvDescription);
		
		NotificationDetails details=lstNotifications.get(position);
		
		tvCaption.setText(details.getCaption());
		tvDescription.setText(details.getDescription());
		
		return convertView;
	}

}
